package Servlet;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.nio.Buffer;

public class HttpServletDemo extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        System.out.println("GET数据提交方式");
        // String getMethod()：获取请求方式： GET
        String method = req.getMethod();
        System.out.println(method);

// String getContextPath()：获取虚拟目录(项目访问路径)
        String contextPath = req.getContextPath();
        System.out.println(contextPath);

// StringBuffer getRequestURL(): 获取URL(统一资源定位符)
        StringBuffer url = req.getRequestURL();
        System.out.println(url.toString());

// String getRequestURI()：获取URI(统一资源标识符)
        String uri = req.getRequestURI();
        System.out.println(uri);

// String getQueryString()：获取请求参数（GET方式）
        String queryString = req.getQueryString();
        System.out.println(queryString);

        //获取请求头: user-agent: 浏览器的版本信息
        String agent = req.getHeader("user-agent");
        System.out.println(agent);
//获取请求头: Host 信息
        String host = req.getHeader("host");
        System.out.println(host);
    }
    @Override
    protected void doPost(HttpServletRequest req,HttpServletResponse resp) throws SecurityException,IOException{
        System.out.println("POST数据提交方式");
        String username = req.getParameter("username");
        String password = req.getParameter("password");
        System.out.println(username);
        System.out.println(password);
    }
}